import Vue from 'vue'
import Vuex from 'vuex'
import { setItem, getItem, remove } from '../utils/storage'

Vue.use(Vuex)

const state = {
  // userInfo: {
  //   username: getItem('userInfo').username,
  //   avatar: getItem('userInfo').avatar
  // }
  userInfo: getItem('userInfo'),
  userList: [],
  messageList: []
}
const mutations = {
  SOCKET_login(state, data) {
    state.userInfo = data
    setItem('userInfo', data)
  },
  SOCKET_getUserList(state, list) {
    state.userList = list
  },
  SOCKET_toChatRoom(state, msg) {
    state.messageList.push(msg)
  },
  Logout(state) {
    remove('userInfo')
    state.userInfo = {}
    state.userList = {}
    state.messageList = []
  }
}
const actions = {}
const getters = {}
const store = new Vuex.Store({
  state,
  mutations,
  actions,
  getters
})

export default store
